<?php // Product ?>
<?php
	$sql = "select a.moduleheading 
			from ms_module a 
			where 	a.stsrc = 'A' 
				and a.modulename = '".$doc_name."' 
				and a.moduleid = '".$doc_id."' 
				and a.modulestatus = 1 
			limit 0,1
			";
	$exe = mysql_query($sql) or die(mysql_error());
	$num = mysql_num_rows($exe);
	$row = mysql_fetch_array($exe);
?>
<div>
	<h2><?php if($num > 0){ echo $row['moduleheading']; } ?></h2>
</div>
<div>
<?php // Get Title(Label), Single Text, View Single Text, title alias

	$uri = $_SERVER['REQUEST_URI'];
	$uri_var = explode('/', $uri);
	
	$count = count($uri_var);
	if(substr($uri,-1,1) == "/")
	{
		$count = $count-2;
	}
	else
	{
		$count = $count-1;
	}
	
	for( $i = 0; $i <= $count; $i++ )
	{
		$var_name[] = "uri_" . $i;
	}
	
	for( $i = 0; $i < $count+1; $i++ )
	{
		${$var_name[$i]}  = $uri_var[$i];
	}

	$string_1 = "";
	$string_2 = "";
	$string_3 = "";
	$string_4 = "";
	$string_5 = "";
	
	if(isset($uri_1)){$string_1 = $uri_1;}	// product
	if(isset($uri_2)){$string_2 = $uri_2;}	// category
	if(isset($uri_3)){$string_3 = $uri_3;}	// brand
	if(isset($uri_4)){$string_4 = $uri_4;}	// class, series
	if(isset($uri_5)){$string_5 = $uri_5;}	// detail
	
	if($string_1 == "product")	// isValid
	{
?>

<?php
		// Detail : Start
		if($string_5 != "" || !empty($string_5))
		{
			$sql = "select a.*, c.filename 
					from tbl_product_detail a 
						left join ms_file c
							on a.productdetailurlimage = c.fileid and c.stsrc = 'A' and c.filerole = 'image' 
					where 	a.stsrc = 'A' 
						and a.productdetailstatus = 1 
						and a.productdetailname = '".$string_5."'
					order by a.productdetailposition asc 
					limit 0,1
					";
			$exe = mysql_query($sql) or die(mysql_error());
			$num = mysql_num_rows($exe);
			$row = mysql_fetch_array($exe);
			
			if($num > 0)
			{
?>
				<div><h3><?php echo stripslashes(html_entity_decode($row['productdetaillabel'])); ?></h3></div>
				<?php
					if($row['productdetailimagestatus'] == 1)
					{
				?>
				<div>
					<img src="<?php echo getURLdomain()."/upload/".$row['filename']; ?>" style="max-width:760px; max-height:760px;" />
				</div>
				<?php
					}
				?>
				<?php if(1==0){ // diremove atas request user Hasyim - 3 Juni 2013  ?>
				<div>
					<p>
						<?php echo stripslashes(html_entity_decode($row['productdetailteaser'])); ?>
					</p>
				</div>
				<?php } ?>
				<div>
					<p>
						<?php echo stripslashes(html_entity_decode($row['productdetaildescription'])); ?>
					</p>
				</div>
				
<?php
			}
		}
		// Detail : End

		// Class : Start
		else if($string_4 != "" || !empty($string_4))
		{
			$sql = "select a.*, c.filename 
					from tbl_product_class a 
						left join ms_file c
							on a.productclassurlimage = c.fileid and c.stsrc = 'A' and c.filerole = 'image' 
					where 	a.stsrc = 'A' 
						and a.productclassstatus = 1 
						and a.productclassname = '".$string_4."'
					order by a.productclassposition asc 
					limit 0,1
					";
			$exe = mysql_query($sql) or die(mysql_error());
			$num = mysql_num_rows($exe);
			$row = mysql_fetch_array($exe);
			
			if($num > 0)
			{
?>
				<div><h3><?php echo stripslashes(html_entity_decode($row['productclasslabel'])); ?></h3></div>
				<div>
					<p>
						<?php
							if($row['productclassimagestatus'] == 1)
							{
						?>
						<img src="<?php echo getURLdomain()."/upload/".$row['filename']; ?>" style="float:left; max-width:300px; max-height:300px; padding:0 5px 10px 0;" />
						<?php
							}
						?>
						<?php echo stripslashes(html_entity_decode($row['productclassdescription'])); ?>
						<div class="clear"></div>
					</p>
				</div>
				<?php
					$sql_list = "select a.productdetailimagestatus, a.productdetailname, a.productdetaillabel, a.productdetailteaser, b.productclassname, c.filename, d.productbrandname, e.productcategoryname
							from tbl_product_detail a 
								left join tbl_product_class b
									on a.productclassid = b.productclassid
								left join ms_file c
									on a.productdetailurlimage = c.fileid and b.stsrc = 'A'
								left join tbl_product_brand d
									on b.productbrandid = d.productbrandid and d.stsrc = 'A'
								left join tbl_product_category e
									on e.productcategoryid = d.productcategoryid and e.stsrc = 'A'
							where a.stsrc = 'A' and a.productdetailstatus = 1 and a.productclassid = ".$row['productclassid']."
							order by a.productdetailposition asc
							
							";
					$exe_list = mysql_query($sql_list) or die(mysql_error());
					$num_list = mysql_num_rows($exe_list);
					
					if($num_list > 0)
					{
				?>
				<div><hr /></div>
				<div><h3><?php echo stripslashes(html_entity_decode($row['productclasslabel'])); ?> Product List</h3></div>
				<div style="padding: 10px 0 20px 0; width:100%;">
					<?php
						$column = 2; // column
						$row_listgap = 20; // pixel
						$width = floor((100-1)/$column); // %, dont change this
						$index = 1; // increment flag, dont change this
						for($i=0;$i<ceil($num_list/$column);$i++)
						{
					?>
							<div style="padding-top:<?php echo $row_listgap; ?>px;">
					<?php
							for($j=1;$j<=$column;$j++)
							{
								if($index <= $num_list)
								{
									$row_list = mysql_fetch_array($exe_list);
					?>
								<div style="float:left; width:<?php echo $width; ?>%; text-align:center;">
									<div style="width:95%; padding:10px 0 10px 0; border:dotted 1px gray;">
										<a href="<?php echo getURLdomain(); ?>/product/<?php echo $row_list['productcategoryname']."/".$row_list['productbrandname']."/".$row_list['productclassname']."/".$row_list['productdetailname']; ?>">
											<?php if($row_list['productdetailimagestatus']){ ?>
											<img src="<?php echo getURLdomain()."/upload/".$row_list['filename']; ?>" style="max-height:150px; max-width:300px;" />
											<?php }else{ ?>
											<img src="<?php echo getURLdomain()."/source/global/img/no-image-100x100.png"; ?>" style="height:100px;" />
											<?php } ?>
										</a>
									</div>
									<div style="width:95%; padding:5px 0 0 0; text-align:left;">
										<span style="font-size:15px; font-weight:bold;"><?php echo $row_list['productdetaillabel']; ?></span>
									</div>
									<div style="width:95%; padding:5px 0 0 0; text-align:left;">
										<span style="font-size:15px;"><?php echo $row_list['productdetailteaser']; ?></span>
									</div>
									<div style="width:95%; padding:10px 0 0 0; text-align:left;">
										<a class="product_view_detail_link" href="<?php echo getURLdomain(); ?>/product/<?php echo $row_list['productcategoryname']."/".$row_list['productbrandname']."/".$row_list['productclassname']."/".$row_list['productdetailname']; ?>">VIEW</a>
									</div>
								</div>
					<?php
									$index++;
								}
							}
					?>
								<div class="clear"></div>
							</div>
					<?php
						}
					?>
				</div>
				<?php
					}
				?>
<?php
			}
		}
		// Class : End

		// Brand : Start
		else if($string_3 != "" || !empty($string_3))
		{
			$sql = "select a.*, c.filename 
					from tbl_product_brand a 
						left join ms_file c
							on a.productbrandurlimage = c.fileid and c.stsrc = 'A' and c.filerole = 'image' 
					where 	a.stsrc = 'A' 
						and a.productbrandstatus = 1 
						and a.productbrandname = '".$string_3."'
					order by a.productbrandposition asc 
					limit 0,1
					";
			$exe = mysql_query($sql) or die(mysql_error());
			$num = mysql_num_rows($exe);
			$row = mysql_fetch_array($exe);
			
			if($num > 0)
			{
?>
				<div><h3><?php echo stripslashes(html_entity_decode($row['productbrandlabel'])); ?></h3></div>
				<div>
					<p>
						<?php
							if($row['productbrandimagestatus'] == 1)
							{
						?>
						<img src="<?php echo getURLdomain()."/upload/".$row['filename']; ?>" style="float:left; max-width:300px; max-height:300px; padding:0 5px 10px 0;" />
						<?php
							}
						?>
						<?php echo stripslashes(html_entity_decode($row['productbranddescription'])); ?>
						<div class="clear"></div>
					</p>
				</div>
				<?php
					$sql_list = "select a.productclassimagestatus, a.productclassname, a.productclasslabel, b.productbrandname, c.filename, e.productcategoryname
							from tbl_product_class a 
								left join tbl_product_brand b
									on a.productbrandid = b.productbrandid
								left join ms_file c
									on a.productclassurlimage = c.fileid and b.stsrc = 'A'
								left join tbl_product_category e
									on e.productcategoryid = b.productcategoryid and e.stsrc = 'A'
							where a.stsrc = 'A' and a.productclassstatus = 1 and a.productbrandid = ".$row['productbrandid']."
							order by a.productclassposition asc
							
							";
					$exe_list = mysql_query($sql_list) or die(mysql_error());
					$num_list = mysql_num_rows($exe_list);
					
					if($num_list > 0)
					{
				?>
				<div><hr /></div>
				<div><h3><?php echo stripslashes(html_entity_decode($row['productbrandlabel'])); ?> Class List</h3></div>
				<div style="padding: 10px 0 20px 0; width:100%;">
					<?php
						$column = 3; // column
						$row_listgap = 5; // pixel
						$width = floor((100-1)/$column); // %, dont change this
						$index = 1; // increment flag, dont change this
						for($i=0;$i<ceil($num_list/$column);$i++)
						{
					?>
							<div style="padding-top:<?php echo $row_listgap; ?>px;">
					<?php
							for($j=1;$j<=$column;$j++)
							{
								if($index <= $num_list)
								{
									$row_list = mysql_fetch_array($exe_list);
					?>
								<div style="float:left; width:<?php echo $width; ?>%; text-align:center;">
									<div>
										<a href="<?php echo getURLdomain(); ?>/product/<?php echo $row_list['productcategoryname']."/".$row_list['productbrandname']."/".$row_list['productclassname']; ?>">
											<?php if($row_list['productclassimagestatus']){ ?>
											<img src="<?php echo getURLdomain()."/upload/".$row_list['filename']; ?>" style="max-height:180px; max-width:180px;" />
											<?php }else{ ?>
											<img src="<?php echo getURLdomain()."/source/global/img/no-image-100x100.png"; ?>" style="height:100px;" />
											<?php } ?>
											<br />
											<?php echo $row_list['productclasslabel']; ?>
											<br />
											<br />
										</a>
									</div>
								</div>
					<?php
									$index++;
								}
							}
					?>
								<div class="clear"></div>
							</div>
					<?php
						}
					?>
				</div>
				<?php
					}
				?>
<?php
			}
		}
		// Brand : End

		// Category : Start
		else if($string_2 != "" || !empty($string_2))
		{
			$sql = "select a.*, c.filename 
					from tbl_product_category a 
						left join ms_file c
							on a.productcategoryurlimage = c.fileid and c.stsrc = 'A' and c.filerole = 'image' 
					where 	a.stsrc = 'A' 
						and a.productcategorystatus = 1 
						and a.productcategoryname = '".$string_2."'
					order by a.productcategoryposition asc 
					limit 0,1
					";
			$exe = mysql_query($sql) or die(mysql_error());
			$num = mysql_num_rows($exe);
			$row = mysql_fetch_array($exe);
			
			if($num > 0)
			{
?>
				<div><h3><?php echo stripslashes(html_entity_decode($row['productcategorylabel'])); ?></h3></div>
				<div>
					<p>
						<?php
							if($row['productcategoryimagestatus'] == 1)
							{
						?>
						<img src="<?php echo getURLdomain()."/upload/".$row['filename']; ?>" style="float:left; max-width:300px; max-height:300px; padding:0 5px 10px 0;" />
						<?php
							}
						?>
						<?php echo stripslashes(html_entity_decode($row['productcategorydescription'])); ?>
						<div class="clear"></div>
					</p>
				</div>
				<?php
					$sql_list = "select a.productbrandimagestatus, a.productbrandname, a.productbrandlabel, b.productcategoryname, c.filename
							from tbl_product_brand a 
								left join tbl_product_category b
									on a.productcategoryid = b.productcategoryid
								left join ms_file c
									on a.productbrandurlimage = c.fileid and b.stsrc = 'A'
							where a.stsrc = 'A' and a.productbrandstatus = 1 and a.productcategoryid = ".$row['productcategoryid']."
							order by a.productbrandposition asc
							
							";
					$exe_list = mysql_query($sql_list) or die(mysql_error());
					$num_list = mysql_num_rows($exe_list);
					
					if($num_list > 0)
					{
				?>
				<div><hr /></div>
				<div><h3><?php echo stripslashes(html_entity_decode($row['productcategorylabel'])); ?> Brand List</h3></div>
				<div style="padding: 10px 0 20px 0; width:100%;">
					<?php
						$column = 3; // column
						$row_listgap = 5; // pixel
						$width = floor((100-1)/$column); // %, dont change this
						$index = 1; // increment flag, dont change this
						for($i=0;$i<ceil($num_list/$column);$i++)
						{
					?>
							<div style="padding-top:<?php echo $row_listgap; ?>px;">
					<?php
							for($j=1;$j<=$column;$j++)
							{
								if($index <= $num_list)
								{
									$row_list = mysql_fetch_array($exe_list);
					?>
								<div style="float:left; width:<?php echo $width; ?>%; text-align:center;">
									<div>
										<a href="<?php echo getURLdomain(); ?>/product/<?php echo $row_list['productcategoryname']."/".$row_list['productbrandname']; ?>">
											<?php if($row_list['productbrandimagestatus']){ ?>
											<img src="<?php echo getURLdomain()."/upload/".$row_list['filename']; ?>" style="max-height:180px; max-width:180px;" />
											<?php }else{ ?>
											<img src="<?php echo getURLdomain()."/source/global/img/no-image-100x100.png"; ?>" style="height:100px;" />
											<?php } ?>
											<br />
											<?php echo $row_list['productbrandlabel']; ?>
											<br />
											<br />
										</a>
									</div>
								</div>
					<?php
									$index++;
								}
							}
					?>
								<div class="clear"></div>
							</div>
					<?php
						}
					?>
				</div>
				<?php
					}
				?>
<?php
			}
		}
		// Category : End

		// Product : Start
		else
		{
			$sql = "select a.*, b.filename
					from tbl_product_category a 
					left join ms_file b
						on a.productcategoryurlimage = b.fileid
					where 	a.stsrc = 'A' 
						and a.productcategorystatus = 1 
					order by a.productcategoryposition asc 
					";
			$exe = mysql_query($sql) or die(mysql_error());
			$num = mysql_num_rows($exe);
			
			
			if($num > 0)
			{
?>
				<div style="padding: 10px 0 20px 0; width:100%;">
					<?php
						$column = 3;
						$index = 1;
						for($i=0;$i<ceil($num/$column);$i++)
						{
					?>
							<div style="padding-top:10px;">
					<?php
							for($j=1;$j<=$column;$j++)
							{
								if($index <= $num)
								{
									$row = mysql_fetch_array($exe);
					?>
								<div style="float:left; width:33.3%; text-align:center;">
									<a href="<?php echo getURLdomain(); ?>/product/<?php echo stripslashes(html_entity_decode($row['productcategoryname'])); ?>">
										<?php if($row['productcategoryimagestatus']){ ?>
										<img src="<?php echo getURLdomain()."/upload/".$row['filename']; ?>" style="max-height:100px; max-width:180px;" />
										<?php }else{ ?>
										<img src="<?php echo getURLdomain()."/source/global/img/no-image-100x100.png"; ?>" style="height:100px;" />
										<?php } ?>
										<br />
										<?php echo stripslashes(html_entity_decode($row['productcategorylabel'])); ?>
										<br />
										<br />
									</a>
								</div>
					<?php
									$index++;
								}
							}
					?>
								<div class="clear"></div>
							</div>
					<?php
						}
					?>
				</div>
<?php
			}
		}
		// Product : End
?>

<?php
	}
?>
</div>